// pages/position/deliver/record.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:-1,
    statusColor: ['#353535', '#999999', '#FE7E3E', '#999999', '#2CA7E7', '#3CC095', '#999999'],
    isLoaded: false,
    isFirstTip: true,
    page: 1,
    size: 10,
    fulltimeList:[],
    hourlyList:[],
    rs: ['未查看', '已查看', '已预约', '预约失败', '已面试', '已入职','面试失败']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.data.id = options.id; // 职位编号
      this.data.type = options.type; // 0：普通职位 1：小时工
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    token = getApp().globalData.token;
    // 重置数据
    this.data.page = 1;
    this.data.fulltimeList = [];
    this.data.hourlyList = [];
    
    if (this.data.type == 0) {
      this.getFullTimeResume();
      wx.setNavigationBarTitle({
        title:'全职简历投递记录'
      })
    } else {
      this.getHourlyResume();
      wx.setNavigationBarTitle({
        title: '小时工简历投递记录'
      })
    }
  },

  getFullTimeResume() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'position/record/list',
      method: 'GET',
      data: {
        token: token,
        positionId: this.data.id,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount == this.data.fulltimeList) {
          this.data.isLoaded = true;
          return ;
        }
        this.setData({
          fulltimeList: this.data.fulltimeList.concat(res.list),
          list: res.list
        })
      }
    })
  },

  getHourlyResume() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'position_hourly/record/list',
      method: 'GET',
      data: {
        token: token,
        positionHourlyId: this.data.id,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount == this.data.hourlyList) {
          this.data.isLoaded = true;
          return;
        }
        this.setData({
          hourlyList: this.data.hourlyList.concat(res.list),
          list: res.list
        })
      }
    })
  },

  /**
   * 简历详情 
   */
  jumpDetails(e) {
    let type = e.currentTarget.dataset.type;
    let param = {
      resumeId: e.currentTarget.dataset.resumeid,
      id: e.currentTarget.dataset.id,
      status: e.currentTarget.dataset.status,
      resumeDeliverId: e.currentTarget.dataset.resumedeliverid
    }
    if (type == 1) { // 全职
      wx.navigateTo({
        url: '/pages/resume/fulltime/detail?'+ T.param(param),
      })
    } else {
      wx.navigateTo({
        url: '/pages/resume/hourly/detail?' + T.param(param),
      })
    }
  },

  onReachBottom: function(){
    if (this.data.isLoadedFull) {
      if (this.data.isFirstTipFull) {
        T.toast({ id: '#toast', text: '还有选项没有填写或者选择,请检查' });
      }
      this.data.isFirstTipFull = false;
      return;
    }
    if (this.data.type == 0) {
      this.data.page += 1;
      this.getFullTimeResume();
    }
    if (this.data.type == 1) {
      this.data.page += 1;
      this.getHourlyResume();
    }
  }
})